package com.MusicWeb.servlet;

import com.MusicWeb.entity.Tip;
import com.MusicWeb.service.TipService;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/tip")
//todo : 用户接受短消息  传入用户的id
//http://localhost:8080/tip?id=?
public class TipSelectServlet extends HttpServlet {
    TipService tipService=new TipService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id=Integer.parseInt(req.getParameter("id"));
        List<Tip> res=tipService.TipSe(id);
        if (res!=null) {
            // 设置返回的数据为json对象
            resp.setContentType("application/json;charset=utf-8");
            // 把实体转换为json，返回给前端
            String str = new Gson().toJson(res);
            resp.getWriter().print(str);
        }
    }
}
